import React, { Component } from 'react'
import { connect } from 'react-redux';
import { Dispatch } from 'redux';
import { add } from '../store/actions';
interface IProps {
    value?: number,
    onadd: () => void,//定义函数
}
class My extends Component<IProps> {
    public render() {
        const { value, onadd } = this.props;
        return (
            <div className="my">
                我的
                <h2>我的组件---{value}</h2>
                <button onClick={() => {
                    onadd();
                }}>点击</button>
            </div>
        )
    }

}
const mapStateToProps = (state: number): { value: number } => ({
    value: state
})
const mapDispatchToProps = (dispatch: Dispatch) => ({
    onadd: () => { dispatch(add()) }
})
export default connect(mapStateToProps, mapDispatchToProps)(My);